var strophe = require('../../utils/strophe.js')
var WebIM = require('../../utils/WebIM.js')
var WebIM = WebIM.default
var app = getApp();
var https = "https://www.moreclub.cn/";
var htp = 'http://more-image.oss-cn-beijing.aliyuncs.com/pinzuominiapp/pinzuoall_bg_';
var v;
var thumb;
var txt;
var leg;
var uid2;
var uid;
var nickName;
var gender;
var sid;
Page({
   data:{
     stopTxt:'结束',
      src: [htp + '6_o.png', htp + '4_y.png', htp + '3_r.png', htp + '2_p.png', htp + '1_g.png', htp + '5_b.png'],
      border: ['1px solid #f8a52c', '1px solid #f6e33e', '1px solid #ef4444', '1px solid #8c32d6', '1px solid #23c114', '1px solid #08cee1'],
     icon: ['pinzuo_6_pgz_black@2x.png', 'pinzuo_4_llt_black@2x.png', 'pinzuo_3_wyx_black@2x.png', 'pinzuo_2_qhd_black@2x.png', 'pinzuo_1_bgm_black@2x.png','pinzuo_5_bsh_black@2x.png'],
     icon2: ['buyuadrink_white@2x.png', 'cocktail_white@2x.png', 'beerbrew_white@2x.png', 'wine_white@2x.png', 'whiskey_white@2x.png', 'importbeer_white@2x.png', 'champagne_white@2x.png', 'brandy_white@2x.png', 'saki_white@2x.png'],
     tent:['拼个座','聊撩天','玩游戏','求回答','帮个忙','憋说话'],
     cont:['','鸡尾酒','精酿啤酒','葡萄酒','威士忌','进口啤酒','香槟','白兰地','清酒'],
     holder: ['一个人喝酒超级无聊，想找好玩朋友拼个座，带我飞。', '聊音乐，电影，酒...认识有趣的你！', '急！玩游戏缺人，求旁边的帅哥靓女加入~', '城市小白，求土著支招好吃的好玩的去处！', '遇见生活小难题，求大神支招！','开车堵，上班老板不酷，回家生活不酷，憋着难受，这里说点酷的！']
   },
   
   onLoad:function(options){
     console.log(options)
      var that = this;
      uid = wx.getStorageSync('uid');
      uid2 = options.uid2;
      thumb = options.thumb
      leg = options.leg
      txt = options.txt
      gender = options.gender
      v = options.cont
      nickName = options.nickName
      var merchantName = options.merchantName
      var timestamp = options.timestamp
      sid = options.sid
      var timestamp1
      var newtime = Math.round(new Date().getTime());
     
      if (timestamp.length==10){
        var timestamp1 = timestamp*1000
      } else if (timestamp.length==13){
        var timestamp1 = timestamp
      }
      var nTime = Math.abs(newtime - timestamp1)
   
      var day = Math.floor(nTime / 86400000);
      var hour = Math.floor(nTime % 86400000 / 3600000);
      var minute = Math.floor(nTime % 86400000 % 3600000 / 60000);
      var time
     
      if (hour >= 1 && hour < 24) {
        var time = hour + '小时前'
      }
      if (day <= 0 && hour < 1 && minute >= 1) {
        var time = minute + '分钟前'
      }
      if (minute < 1 && day < 1 && hour < 1) {
        var time = '刚刚'
      }
      if (day > 0) {
        var time = day + '天前'
      }

     
    
      that.setData({
        thumb:thumb,
        leg:leg,
        txt: txt,
        v: v,
        nickName: nickName,
        merchantName: merchantName,
        time:time,
        uid:uid,
        gender:gender,
        uid2:uid2,
        sid:sid
      })

      
     
   } ,
   stop:function(){
     var access_token = wx.getStorageSync('inToken');
     wx.request({
       url: https + 'v2/signinter/close?sid=' + sid+'&access_token=' + access_token,
       method: 'DELETE',
       header: {
         'content-type': 'application/json'
       },
       data: {
         'sid': sid,
         'access_token': access_token

       },
       success: function (res) {
         console.log(res)
       }
     })  

     wx.removeStorage({
       key: 'v',
       success: function (res) {
         //console.log(res.data)
       }
     })  

     this.setData({
       stopTxt:'已结束'
     })
   },

   send: function (e) {
     var access_token = wx.getStorageSync('inToken');
     var uid = wx.getStorageSync('uid');
     var myName = wx.getStorageSync('myUsername')
     console.log(nickName)
    
       var nameList = {
         myName: myName,
         your: uid2,
         yourName: nickName,
         userAvatar: thumb
       }
      
     wx.navigateTo({
       url: '../chat/chat?username=' + JSON.stringify(nameList) 
     })

   },
   
})  